﻿package com.toncen.samepms.system.dao;

import java.sql.Connection;
import java.util.List;

import com.toncen.samepms.common.AbstractDao;
import com.toncen.samepms.system.domain.Code;

/**
 * 描述：编码表SYSTEM_CODE的dao文件
 * 
 * @author tch
 */
public class CodeDao extends AbstractDao<Code> {

	public CodeDao() {
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.toncen.samepms.common.AbstractDao#delete(long)
	 */
	@Override
	public int delete(long id) throws Exception {
		Code code = find(id);
		if (code != null) {
			new CodeItemDao().delete(code.getCodeItemList());// 级联删除明细
		}
		return super.delete(id);
	}

	/**
	 * @param code
	 * @return
	 * @throws Exception
	 */
	public Code getByCode(String code) throws Exception {
		return (Code) getSqlMap().queryForObject(getStatement("getByCode"), code);
	}

	/**
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public List<Code> getAll() throws Exception {
		return findList("getAll", null);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.comit.common.db.BaseDao#initialize()
	 */
	@Override
	protected void initialize() {
		setStatementPrefix("Code");
		setStatementDivision(".");
	}

	/**
	 * 
	 * 
	 * @return
	 * @throws Exception
	 */
	public Connection getConnection() throws Exception {
		return getSqlMap().getDataSource().getConnection();
	}
}
